#ifndef LIGHT_H_
#define LIGHT_H_

#include "Vec4.h"
#include "SmartPtr.h"

class File;
/* A brief attempy at controlling the OpenGl light commands */

/* TO DO:- 
        * Make this a base class and have a derived spotlight, 
          ambient and point light class
*/

class Light : public RefCounted
{
public:
    /* Default Ctr*/
    Light();
    
    /* Load in data from external source 
     * Not yet implemented */
    bool Load(File* file);
    /* Large Set Function */
    void SetAll(const Vec4f& pos,           const Vec4f& ambient,
                const Vec4f& diffuse,       const Vec4f& specular,
                const Vec3f& direction,     const float& cutOffAngle, 
                const float& exponent,      const float& cAttenuation, 
                const float& lAttenuation,  const float& qAttenuation, 
                const bool drawn,           const bool spotlight,
                const bool attenuated,      const int ID);

    /* Set up to be called in Draw functions */
    void SetUp() const;
    /* Render a sphere at the lights location */
    void Draw() const;
    /* Gl Enable or Disable */
    void TurnOn();
    void TurnOff();

    /* Returns LIGHT0 + m_id */
    const int GetId() const;

    /* Set functions */
    void SetId(int id);
    void ShouldDraw(bool draw);
    void ShouldSpot(bool spot);
    void ShouldAttenuate(bool att);

    void SetAmbient     (const Vec4f& amb);
    void SetDiffuse     (const Vec4f& dif);
    void SetSpecular    (const Vec4f& spc);
    void SetDirection   (const Vec3f& dir);
    void SetPosition    (const Vec4f& pos);
    void SetCutOffAngle (const float& ang);
    void SetExponent    (const float& exp);
    void SetCAttenuation(const float& att);
    void SetLAttenuation(const float& att);
    void SetQAttenuation(const float& att);

    /* Get Functions */
    Vec3f CopyPos() const;
    const Vec3f& GetDirection() const;

private:
    /* if w is 0, it is directional light, and x,y,z represent its direction
     * if 1 it is a positional light, and x,y,z represent its position */
    Vec4f m_pos;
    Vec4f m_ambient;
    Vec4f m_diffuse;
    Vec4f m_specular;
    Vec3f m_direction;
    /* The distance from the direction vector that the light is shown too*/
    float m_cutOffAngle;
    /* A higher exponent value gives a more focused light */
    float m_exponent;
    /* Attenuation values used to affect Ambient, spec and diffuse values
     * Based on distance from source to target */
    //constant attenuation
    float m_cAttenuation;
    //linear attenuation
    float m_lAttenuation;
    //quadratic attenuation
    float m_qAttenuation;

    bool m_drawn;
    bool m_spotlight;
    bool m_attenuated;

    int m_id;
};

typedef SmartPtr<Light> pLight;

#endif